package com.swedne.test.udp;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

public class SendClient {
    public static void main(String[] args) {
        String url = "/talk/broadcast/data";
        String body = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" +
                "<event>\n" +
                "\t<broadcast_url>elevaction</broadcast_url>\n" +
                "\t<elev>\n" +
                "\t\t<to>12</to>\n" +
                "\t\t<build>1</build>\n" +
                "\t\t<unit>0</unit>\n";
        String body2 = "\t\t<floor>12</floor>\n" +
                "\t\t<family>4</family>\n" +
                "\t</elev>\n" +
                "\t<active>broadcast_data</active>\n" +
                "\t<type>req</type>\n" +
                "</event>\n" +
                "receiver success runnint\n";

        String body3 = "<?xml version=\"1.0\"  encoding=\"UTF-8\"?>\n" +
                "<event> \n" +
                " <broadcast_url>/access/forceopen</broadcast_url> \n" +
                " <devmfrs>DNAKE</devmfrs>\n" +
                "<data>1</data>\n" +
                "<active>broadcast_data</active>\n" +
                "<type>req</type>\n" +
                "</event>\n";
        String body4 = "<?xml version=\"1.0\"  encoding=\"UTF-8\"?>\n" +
                "<event> \n" +
                " <broadcast_url>/fermax/clearmode</broadcast_url> \n" +
                "<id>9908</id>\n" +
                "<active>broadcast_data</active>\n" +
                "<type>req</type>\n" +
                "</event>\n";
        String body5 = "<?xml version=\"1.0\"  encoding=\"UTF-8\"?>\n" +
                "<event> \n" +
                " <broadcast_url>/elev/visit</broadcast_url> \n" +
                "<elev>" +
                "<from>1010801</from>" +
                "<to>1012002</to>" +
                "</elev>\n" +
                "<active>broadcast_data</active>\n" +
                "<type>req</type>\n" +
                "</event>\n";
        String body6 = "<?xml version=\"1.0\"  encoding=\"UTF-8\"?>\n" +
                "<event> \n" +
                " <broadcast_url>elev</broadcast_url> \n" +
                "<elev>" +
                "<build>1</build>" +
                "<device>1</device>" +
                "<message>HELLO1</message>" +
                "</elev>\n" +
                "<active>broadcast_data</active>\n" +
                "<type>req</type>\n" +
                "</event>\n";
        String alarmManager = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" +
                "<event>\n" +
                "\t<broadcast_url>security</broadcast_url>\n" +
                "\t<data>\n" +
                "\t\t<io>0</io>\n" +
                "\t\t<type>2</type>\n" +
                "\t\t<sensor>0</sensor>\n" +
                "\t</data>\n" +
                "\t<talk>\n" +
                "\t\t<build>23</build>\n" +
                "\t\t<unit>1</unit>\n" +
                "\t\t<floor>11</floor>\n" +
                "\t\t<family>11</family>\n" +
                "\t</talk>\n" +
                "\t<active>broadcast_data</active>\n" +
                "\t<type>req</type>\n" +
                "</event>";

        String fermaxMode="<event>\n" +
                "\t<broadcast_url>/fermax/setmode</broadcast_url>\n" +
                "\t<id>9901</id>\n" +
                "\t<mode>1</mode>\n" +
                "\t<wall>1</wall>\n" +
                "\t<unit>23</unit>\n" +
                "\t<url>sip:9901@192.168.14.201,sip:123@sip.fermax.com</url>\n" +
                "\t<transferNum>-1</transferNum>\n" +
                "\t<active>broadcast_data</active>\n" +
                "\t<type>req</type>\n" +
                "</event>>";
//        String sendMsg = "POST " + url + " MSG/1.0\r\n\r\n" + body+body2;
//        String sendMsg = "POST " + url + " MSG/1.0\r\n\r\n" + body3;
        String sendMsg = fermaxMode;
        byte[] data = new byte[128 * 1024];
        try {
            DatagramSocket ds = new DatagramSocket();
//            DatagramPacket dp = new DatagramPacket(data, data.length, InetAddress.getByName("238.9.9.1"), 8400);
            DatagramPacket dp = new DatagramPacket(data, data.length, InetAddress.getByName("192.168.14.255"), 8400);
            dp.setData(sendMsg.getBytes());
            ds.send(dp);
            System.out.println("send success//" + sendMsg);
        } catch (IOException e) {
            e.printStackTrace();
            System.out.println("send  IOException");
            return;
        }
    }
}
